package com.mes_for_xxxxxx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mes_for_xxxxxx.entity.Process;
import com.mes_for_xxxxxx.entity.Workshop;
import com.mes_for_xxxxxx.mapper.WorkshopMapper;
import com.mes_for_xxxxxx.service.IProcessService;
import com.mes_for_xxxxxx.service.IWorkshopService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 车间信息表，存储车间相关信息 服务实现类
 * </p>
 *
 * @author 179005
 * @since 2024-09-10
 */
@Service
public class WorkshopServiceImpl extends ServiceImpl<WorkshopMapper, Workshop> implements IWorkshopService {
    @Autowired
    private IProcessService processService;

    @Override
    public Workshop getWorkShopByFlow(String route_id, String flow) {
        QueryWrapper<Process> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("route_id", route_id);
        queryWrapper.eq("produce_name", flow);
        Process process = processService.getOne(queryWrapper);
        Integer nextProduceId = process.getNextProduceId();
        if(nextProduceId == null){
            return null;
        }

        QueryWrapper<Workshop> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("produce_id", nextProduceId);
        return getOne(queryWrapper2);
    }
}
